package me.zhengjie.sqlservice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import me.zhengjie.mapper.LiftWaitPointMapper;
import me.zhengjie.pojo.entity.LiftWaitPoint;
import me.zhengjie.sqlservice.LiftWaitPointService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class LiftWaitPointServiceImpl extends ServiceImpl<LiftWaitPointMapper, LiftWaitPoint> implements LiftWaitPointService {
    private final LiftWaitPointMapper liftWaitPointMapper;

    @Override
    public boolean insertLiftWaitPoint(LiftWaitPoint liftWaitPoint) {
        return liftWaitPointMapper.insert(liftWaitPoint) >0;
    }

    @Override
    public List<LiftWaitPoint> selectAll() {
        return liftWaitPointMapper.selectList(null);
    }

    @Override
    public List<LiftWaitPoint> selectElevatorFloorTask(String floor) {
        LambdaQueryWrapper<LiftWaitPoint> liftWaitPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
        liftWaitPointLambdaQueryWrapper.eq(LiftWaitPoint::getStartFloor,floor);
        return liftWaitPointMapper.selectList(liftWaitPointLambdaQueryWrapper);
    }

    @Override
    public boolean removeId(Integer id) {
        return liftWaitPointMapper.deleteById(id) >0;
    }

    @Override
    public List<LiftWaitPoint> selectLiftCode(String liftCode) {
        LambdaQueryWrapper<LiftWaitPoint> liftWaitPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
        liftWaitPointLambdaQueryWrapper.eq(LiftWaitPoint::getLiftCode,liftCode)
                .orderByAsc(LiftWaitPoint::getCreateTime);
        return liftWaitPointMapper.selectList(liftWaitPointLambdaQueryWrapper);
    }

    @Override
    public List<LiftWaitPoint> selectFloor(String floor) {
        LambdaQueryWrapper<LiftWaitPoint> liftWaitPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
        liftWaitPointLambdaQueryWrapper.eq(LiftWaitPoint::getStartFloor,floor);
        return liftWaitPointMapper.selectList(liftWaitPointLambdaQueryWrapper);
    }
}
